package com.mzj.saas.mservice.house.repository;

import com.mzj.saas.mservice.house.entity.HouseMatchUser;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

public interface HouseMatchUserRepository extends PagingAndSortingRepository<HouseMatchUser, Long>, JpaSpecificationExecutor<HouseMatchUser> {
    List<HouseMatchUser> findByHouseIdInAndStatus(List<String> houseIds, Integer status);

    List<HouseMatchUser> findByMatchUserIdAndStatus(String matchUserId, Integer status);

    HouseMatchUser findByApplyIdAndStatus(Long applyId,Integer status);

    @Query("SELECT u FROM HouseMatchUser u WHERE u.houseId = ?1 AND u.status=?2")
    List<HouseMatchUser> findHouseIdAndStatus(String houseId, Integer status);
    
    @Query("SELECT u FROM HouseMatchUser u WHERE (u.matchUserId = ?1 or u.matchUserId = ?2) and u.houseId = ?3 and u.status=?4")
    HouseMatchUser findByMatchUserIdOrMatchUserIdAndStatus(String matchUserId1, String matchUserId2, String houseId, Integer status);

    HouseMatchUser findByHouseIdAndApplyIdAndMatchUserId(String houseId,Long applyId,String matchUserId);

    List<HouseMatchUser> findByApplyIdAndMatchUserId(Long applyId,String matchUserId);

    @Modifying
    @Query(value = "UPDATE saas_house_match_user SET status = 2 WHERE house_id=?1",nativeQuery = true)
    Integer updateStatusByHouseId(String houseId);

    List<HouseMatchUser> findByHouseIdAndMatchUserIdAndStatus(String houseId,String matchUserId,Integer status);
}
